//
//  LoginViewController.m
//  PlayCatchGame
//
//  Created by 流言 on 2018/1/15.
//  Copyright © 2018年 清正. All rights reserved.
//

#import "LoginViewController.h"
#import "AppHeader.h"

#import "PhoneLoginVC.h"
#import <WXApi.h>


@interface LoginViewController () {
    
    __weak IBOutlet NSLayoutConstraint *topSpace;
    __weak IBOutlet NSLayoutConstraint *top1Space;
}

@property (copy, nonatomic) LoginTypeBlock loginBlock;


@property (weak, nonatomic) IBOutlet UIButton *wxButton;
@property (weak, nonatomic) IBOutlet UIButton *phoneBtn;
@property (weak, nonatomic) IBOutlet UIButton *protocolBtn;
@property (weak, nonatomic) IBOutlet UIButton *closeButton;

@end

@implementation LoginViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}
/// 强制状态栏颜色
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (IS_IPHONE_6 || IS_IPHONE_6PLUS) {
        topSpace.constant =top1Space.constant =70;
    } else if (IS_IPHONE_X) {
        topSpace.constant =top1Space.constant =90;
    }
}

+ (void)gotoLoginViewController:(UIViewController *)presentVC loginType:(LoginTypeBlock)newBlock {
    LoginViewController *loginVC =[[LoginViewController alloc]init];
    loginVC.title =@"登录";
    loginVC.hidesBottomBarWhenPushed =YES;
    loginVC.loginBlock = newBlock;
    
    BaseNavController *loginNav =[[BaseNavController alloc]initWithRootViewController:loginVC];
    [presentVC presentViewController:loginNav animated:YES completion:nil];
}

- (IBAction)didButtonClick:(UIButton *)sender {
    if (sender ==self.closeButton) {
        [self backBeforeVC:NO];
    } else if (sender ==self.protocolBtn) {
        
    } else if (sender ==self.wxButton) {
        
        //构造SendAuthReq结构体
        SendAuthReq* req =[[SendAuthReq alloc]init];
        req.scope = @"snsapi_userinfo";
        req.state = @"123";
        //第三方向微信终端发送一个SendAuthReq消息结构
        [WXApi sendReq:req];

        
    } else if (sender ==self.phoneBtn) {
        PhoneLoginVC *phoneVC =[[PhoneLoginVC alloc]init];
        phoneVC.title =@"登录";
        [self.navigationController pushViewController:phoneVC animated:YES];
    }
}

#pragma mark - Private Method - wxLogin


- (void)backBeforeVC:(BOOL)success {
    [self dismissViewControllerAnimated:YES completion:^{
        self.loginBlock(success);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
